package com.ruoyi.system.dto.convert;

import com.ruoyi.system.dto.ContructionProjectAddOrUpdateDTO;
import com.ruoyi.system.dto.ContructionProjectDTO;
import com.ruoyi.system.entity.ConstructionProjectDO;
import com.ruoyi.system.vo.ProjectDetailVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 施工项目类型转换器（DTO ↔ DO ↔ VO）
 */
@Mapper(componentModel = "spring") // 支持Spring依赖注入
public interface ContructionProjectConverter {

    // 单例实例（MapStruct自动生成实现类）
    ContructionProjectConverter INSTANCE = Mappers.getMapper(ContructionProjectConverter.class);

    /**
     * 新增/修改DTO 转 DO（忽略ID、创建时间等自动填充字段）
     */
    @Mappings({
            @Mapping(target = "id", ignore = true),
            @Mapping(target = "projectCode", ignore = true),
            @Mapping(target = "projectStatus", ignore = true),
            @Mapping(target = "pauseReason", ignore = true),
            @Mapping(target = "currentStageId", ignore = true),
            @Mapping(target = "currentStageName", ignore = true),
            @Mapping(target = "createBy", ignore = true),
            @Mapping(target = "createTime", ignore = true),
            @Mapping(target = "updateBy", ignore = true),
            @Mapping(target = "updateTime", ignore = true),
            @Mapping(target = "isDeleted", ignore = true)
    })
    ConstructionProjectDO addOrUpdateDtoToDo(ContructionProjectAddOrUpdateDTO dto);

    /**
     * DO 转 列表返回DTO
     */
    @Mappings({
            @Mapping(target = "projectStatusText", ignore = true) // 状态文本需手动处理
    })
    ContructionProjectDTO doToListDto(ConstructionProjectDO projectDO);

    /**
     * DO 转 详情VO（基础字段映射，阶段/团队/事项需补充）
     */
    ProjectDetailVO doToDetailVo(ConstructionProjectDO projectDO);

    /**
     * DO列表 转 列表DTO列表
     */
    List<ContructionProjectDTO> doListToListDtoList(List<ConstructionProjectDO> projectDOList);
}